home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / manchest.lha / MANCHESTER / manchester / 4.1 / keepCursorInView.st < prev    next >
Text File  |  1993-07-24  |  4KB  |  122 lines

  1. "    NAME        keepCursorInView
  2.     AUTHOR        Bernard Horan <bernard@is.morgan.com>
  3.     CONTRIBUTOR    Bernard Horan <bernard@is.morgan.com>
  4.     FUNCTION      Changes to DialogView to keep cursor in view
  5.     ST-VERSIONS    4.1
  6.     PREREQUISITES     
  7.     CONFLICTS     
  8.     DISTRIBUTION    global
  9.     VERSION        2.0
  10.     DATE        September 1992
  11.     SUMMARY        In versions prior to 4.0, Smalltalk contained
  12. methods to keep the cursor in a view (i.e. a window), forcing a
  13. single-thread dialogue.  This changes file adds extra methods to
  14. controller to offer that facility again.  An extra instance variable
  15. ('modal') has been added to the class DialogController to set
  16. 'modalness'.  This change set now forces fillInTheBlank and yesNo
  17. windows to be modal.  The changes to enforce this are trivial, and are
  18. contained in the method 'open' The change works OK on Macs in single
  19. and multifinder, however under OpenWindows it's best to have the
  20. clickSelect option for window selection.  BH, 25/9/92"!
  21.  
  22. 'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992 on 25 September 1992 at 7:29:18 am'!
  23.  
  24.  
  25.  
  26. !DialogView methodsFor: 'interaction'!
  27.  
  28. open
  29.     " Interact with the user. "
  30.     "Default to modal dialog.
  31.     Bernard Horan, 25 September 1992"
  32.  
  33.     self openType: #dialog modal: true!
  34.  
  35. openType: windowType modal: aBoolean
  36.     " Interact with the user. "
  37.     "If aBoolean is true, then keep the cursor in the view.
  38.     Bernard Horan, 25 September 1992"
  39.  
  40.     | borderWidth wrapper topView box |
  41.     borderWidth := 2.
  42.     wrapper := BorderedWrapper on: self.
  43.     wrapper border: (Border width: borderWidth).
  44.     topView := ScheduledWindow new.
  45.     topView component: wrapper.
  46.     topView controller: (DialogController new modal: aBoolean).
  47.     topView model: self closeChannel.
  48.     box := wrapper preferredBounds.
  49.     box := box
  50.             align: box center
  51.             with: WindowSensor cursorPoint.
  52.     topView openTransientIn: box type: windowType! !
  53.  
  54. StandardSystemController subclass: #DialogController
  55.     instanceVariableNames: 'modal '
  56.     classVariableNames: ''
  57.     poolDictionaries: ''
  58.     category: 'Interface-Dialogs'!
  59.  
  60. DialogController comment:
  61. 'Class DialogController keeps control until the model answers true to the message value.
  62.  
  63. In addition, it keeps the cursor in the view if the variable modal is set to true.
  64. Bernard Horan, 25 September 1992
  65. '!
  66.  
  67.  
  68. !DialogController methodsFor: 'initialize-release'!
  69.  
  70. initialize
  71.     "Initialize the receiver.
  72.     bernard Horan, 25 September 1992"
  73.     super initialize.
  74.     self modal: false! !
  75.  
  76. !DialogController methodsFor: 'accessing'!
  77.  
  78. modal
  79.     "Bernard Horan, 25 September 1992"
  80.     ^modal!
  81.  
  82. modal: aBoolean 
  83.     "Bernard Horan, 25 September 1992"
  84.  
  85.     modal := aBoolean! !
  86.  
  87. !DialogController methodsFor: 'control defaults'!
  88.  
  89. isControlActive
  90.     "Answer true as long as the dialog is not finished."
  91.     "Also, make sure that the cursor is kept in the view if the modal flag is true.
  92.     Bernard Horan, 25 September 1992"
  93.  
  94.     self isFinished ifTrue: [^false].
  95.     self modal ifTrue: [ [self viewHasCursor] whileFalse:[self keepCursorInView]].
  96.     ^true! !
  97.  
  98. DialogController organization changeFromString: '(''initialize-release'' #initialize)
  99. (''accessing'' #modal #modal: #restartAfterError #shutdownBecauseOfError)
  100. (''control defaults'' #close #controlActivity #controlInitialize #controlTerminate #isControlActive)
  101. (''private'' #isFinished)
  102. '!
  103.  
  104.  
  105.  
  106. !Controller methodsFor: 'cursor'!
  107.  
  108. keepCursorIn: aRectangle 
  109.     "Bernard Horan, 25 September 1992"
  110.  
  111.     | aPoint curPt |
  112.     aPoint := ((curPt := self sensor cursorPoint) max: aRectangle origin)
  113.                 min: aRectangle corner.
  114.     aPoint = curPt ifFalse: [self sensor cursorPoint: aPoint]!
  115.  
  116. keepCursorInView
  117.     "Bernard Horan, 25 September 1992"
  118.  
  119.     ^self keepCursorIn: (view bounds insetBy: (0@0 extent: 1@1))! !
  120.  
  121.  
  122.